﻿Imports System.Data
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraSplashScreen

Public Class PhieuXuat
    Private state As Integer '0 default 1 tao moi 2 sua
    Private Sub setReadOnly(ByVal b As Boolean)
        Me.MaTextEdit.Properties.ReadOnly = b
        Me.SohoadonTextEdit.Properties.ReadOnly = b
        Me.KhachhangSearchLookUpEdit.Properties.ReadOnly = b
        Me.NghiepvuTextEdit.Properties.ReadOnly = b
        Me.DiachiTextEdit.Properties.ReadOnly = b
        Me.ThuesuatTextEdit.Properties.ReadOnly = b
        Me.NgayhoadonDateEdit.Properties.ReadOnly = b
        Me.NgaythanhtoanDateEdit.Properties.ReadOnly = b
        Me.NgayxuatDateEdit.Properties.ReadOnly = b
        If b Then
            ' không cho phép chỉnh sửa trên lưới
            Me.IGridView1.OptionsBehavior.Editable = False
            'không cho thêm dòng trống dưới cùng
            Me.IGridView1.OptionsView.NewItemRowPosition = NewItemRowPosition.None
        Else
            ' cho phép chỉnh sửa trên lưới
            Me.IGridView1.OptionsBehavior.Editable = True
            ' cho thêm dòng trống dưới cùng
            Me.IGridView1.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom
        End If
    End Sub
    Private Sub chophepButtonLuuXoa(ByVal b As Boolean)
        Me.BarButtonItemLuu.Enabled = b
        Me.BarButtonItemXoa.Enabled = b
        If b Then
            Me.BarButtonItemSua.Enabled = False
        Else
            Me.BarButtonItemSua.Enabled = True
        End If
    End Sub
    Private Sub chophepButtonChiTiet(ByVal b As Boolean)
        Me.BarButtonItemTaoMoiChiTiet.Enabled = b
        Me.BarButtonItemXoaChiTiet.Enabled = b
        Me.BarButtonItemHuyThayDoiChiTiet.Enabled = b
    End Sub
    Private Sub PhieuXuat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SplashScreenManager.ShowForm(GetType(WaitForm1))
        Me.DonvitinhTableAdapter.Fill(Me.PcvgppDataSet.donvitinh)
        Me.Hanghoa_donvitinhTableAdapter.Fill(Me.PcvgppDataSet.hanghoa_donvitinh)
        Me.HanghoaTableAdapter.Fill(Me.PcvgppDataSet.hanghoa)
        Me.KhachhangTableAdapter.Fill(Me.PcvgppDataSet.khachhang)
        Me.XuatTableAdapter.Fill(Me.PcvgppDataSet.xuat)
        Me.XuatchitietTableAdapter.Fill(Me.PcvgppDataSet.xuatchitiet)
        Me.setReadOnly(True)
        Me.chophepButtonLuuXoa(False)
        Me.chophepButtonChiTiet(False)
        Me.IGridView1.BestFitColumns()
        Me.XuatBindingSource.MoveLast()
        Me.state = 0
        SplashScreenManager.CloseForm()
    End Sub


    Private Sub BarButtonItemTaoMoi_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemTaoMoi.ItemClick
        Try
            Me.setReadOnly(False)
            Me.chophepButtonLuuXoa(True)
            Me.chophepButtonChiTiet(True)
            Me.MaTextEdit.Focus()
            Me.XuatBindingSource.AddNew()
            Me.XuatchitietBindingSource.AddNew()
            Me.state = 1
        Catch ex As Exception

        End Try
    End Sub

    Private Sub BarButtonItemLuu_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLuu.ItemClick
        Try
            Me.IGridView1.CloseEditor()
            Me.XuatBindingSource.EndEdit()
            Me.FKxuatchitietxuatBindingSource.EndEdit()
            If Me.PcvgppDataSet.HasChanges Then
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn 'Lưu' không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Me.XuatTableAdapter.Update(Me.PcvgppDataSet.xuat)
                    Me.XuatchitietTableAdapter.Update(Me.PcvgppDataSet.xuatchitiet)
                    Me.setReadOnly(True)
                    Me.chophepButtonLuuXoa(False)
                    Me.chophepButtonChiTiet(False)
                    Me.state = 0
                End If
            Else
                DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có thông tin để lưu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Me.setReadOnly(True)
                Me.chophepButtonLuuXoa(False)
                Me.chophepButtonChiTiet(False)
                Me.state = 0
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BarButtonItemSua_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemSua.ItemClick
        Me.setReadOnly(False)
        Me.chophepButtonLuuXoa(True)
        Me.chophepButtonChiTiet(True)
        Me.state = 2
    End Sub

    Private Sub BarButtonItemXoa_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemXoa.ItemClick
        If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn 'Xóa' không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
            Me.XuatBindingSource.RemoveCurrent()
            Me.XuatTableAdapter.Update(Me.PcvgppDataSet.xuat)
            Me.setReadOnly(True)
            Me.chophepButtonLuuXoa(False)
            Me.chophepButtonChiTiet(False)
        End If
    End Sub

    Private Sub BarButtonItemHuyThayDoi_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemHuyThayDoi.ItemClick
        Me.XuatBindingSource.EndEdit()
        If Me.PcvgppDataSet.HasChanges Then
            If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn hủy tất cả những thay đổi đang làm không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                Me.PcvgppDataSet.RejectChanges()
            End If
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có dữ liệu thay đổi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End If
    End Sub

    Private Sub BarButtonItemFirst_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemFirst.ItemClick
        Me.XuatBindingSource.MoveFirst()
    End Sub

    Private Sub BarButtonItem2_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick
        Me.XuatBindingSource.MovePrevious()
    End Sub

    Private Sub BarButtonItem6_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem6.ItemClick
        Me.XuatBindingSource.MoveNext()
    End Sub

    Private Sub BarButtonItem7_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem7.ItemClick
        Me.XuatBindingSource.MoveLast()
    End Sub

    Private Sub BarButtonItemThoat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemThoat.ItemClick
        Me.Close()
    End Sub

    Private Sub BarButtonItemTaoMoiChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemTaoMoiChiTiet.ItemClick
        Me.IGridView1.Focus()
        Me.IGridView1.AddNewRow()
        Me.batFocus()
    End Sub

    Private Sub BarButtonItemXoaChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemXoaChiTiet.ItemClick
        If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
            Dim view As GridView = CType(IGridView1, GridView)
            view.DeleteRow(view.FocusedRowHandle)
        End If
    End Sub

    Private Sub BarButtonItemHuyThayDoiChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemHuyThayDoiChiTiet.ItemClick
        Me.IGridView1.CloseEditor()
        Me.FKxuatchitietxuatBindingSource.EndEdit()
        If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn hủy những thay đổi đang làm không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
            Me.PcvgppDataSet.RejectChanges()
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có dữ liệu thay đổi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub BarButtonItemFirstChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemFirstChiTiet.ItemClick
        Me.FKxuatchitietxuatBindingSource.MoveFirst()
    End Sub

    Private Sub BarButtonItemPreviousChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemPreviousChiTiet.ItemClick
        Me.FKxuatchitietxuatBindingSource.MovePrevious()
    End Sub

    Private Sub BarButtonItemNextChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemNextChiTiet.ItemClick
        Me.FKxuatchitietxuatBindingSource.MoveNext()
    End Sub

    Private Sub BarButtonItemLastChiTiet_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLastChiTiet.ItemClick
        Me.FKxuatchitietxuatBindingSource.MoveLast()
    End Sub

    Private Sub NgayhoadonDateEdit_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NgayhoadonDateEdit.GotFocus
        Me.NgayhoadonDateEdit.ShowPopup()
    End Sub

    Private Sub NgaythanhtoanDateEdit_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NgaythanhtoanDateEdit.GotFocus
        Me.NgaythanhtoanDateEdit.ShowPopup()
    End Sub

    Private Sub NgayxuatDateEdit_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NgayxuatDateEdit.GotFocus
        Me.NgayxuatDateEdit.ShowPopup()
    End Sub

    Private Function ktMaTonTai() As Boolean

        For index = 0 To Me.IGridView1.RowCount - 1
            If Me.IGridView1.GetRowCellValue(index, "ma") = Me.MaTextEdit.EditValue Then
                Return True
                Exit Function
            End If

        Next
        Return False
    End Function

    Private Sub MaTextEdit_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MaTextEdit.Validating
        If ktMaTonTai() And state Then
            Me.MaTextEdit.ErrorText = "Mã đã tồn tại"
            e.Cancel = True
        End If
    End Sub

    Private Sub batFocus()
        Me.IGridView1.FocusedRowHandle = 2
        Me.IGridView1.FocusedColumn = Me.IGridView1.VisibleColumns(0)
        Me.IGridView1.ShowEditor()
    End Sub
    Private Sub IGridView1_InvalidValueException(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.InvalidValueExceptionEventArgs) Handles IGridView1.InvalidValueException
        e.ExceptionMode = DevExpress.XtraEditors.Controls.ExceptionMode.DisplayError
    End Sub
    Private Sub IGridView1_InvalidRowException(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.InvalidRowExceptionEventArgs) Handles IGridView1.InvalidRowException
        e.ExceptionMode = DevExpress.XtraEditors.Controls.ExceptionMode.NoAction
    End Sub

    Private Sub IGridView1_ShownEditor(ByVal sender As Object, ByVal e As System.EventArgs) Handles IGridView1.ShownEditor
        Dim view As GridView = CType(sender, GridView)
        If TypeOf view.ActiveEditor Is SearchLookUpEdit And IsDBNull(Me.IGridView1.FocusedValue) Then
            DirectCast(view.ActiveEditor, SearchLookUpEdit).ShowPopup()
        End If
        Dim view1 As ColumnView = CType(sender, ColumnView)
        view1.ActiveEditor.IsModified = True
    End Sub

    Private Sub IGridView1_ValidateRow(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs) Handles IGridView1.ValidateRow
        Dim view As ColumnView = CType(sender, ColumnView)
        Dim tenhanghoa As GridColumn = view.Columns("tenhanghoa")
        Dim sErr As String = ""
        Dim bVali As Boolean = True
        ' kiem tra 2 cell cua mot dong dang Edit xem co rong ko?

        If IGridView1.GetRowCellValue(e.RowHandle, "hanghoa").ToString() = "" Then
            bVali = False
            'sErr = sErr & "Vui long dien Ma hàng"
            view.SetColumnError(tenhanghoa, "tên hàng hóa không được rỗng")
        End If
        If IGridView1.GetRowCellValue(e.RowHandle, "tenhanghoa").ToString() = "" Then
            bVali = False
            'sErr = sErr & "Vui long dien Ten hàng"
            view.SetColumnError(tenhanghoa, "tên hàng hóa không được rỗng")
        End If
        If bVali = True Then
        Else
            e.Valid = False
        End If
    End Sub

    Private Sub IGridView1_ValidatingEditor(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles IGridView1.ValidatingEditor
        Dim View As GridView = sender
        If View.FocusedColumn.FieldName = "hanghoa" And View.FocusedRowHandle <> -999997 Then
            'If e.Value Is DBNull.Value Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "Mã hàng hóa không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString = "" Then
                e.ErrorText = "Mã hàng hóa không được rỗng !"
                e.Valid = False
            End If
        End If
        If View.FocusedColumn.FieldName = "tenhanghoa" And View.FocusedRowHandle <> -999997 Then
            'If e.Value Is DBNull.Value Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "Tên hàng hóa không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString = "" Then
                e.ErrorText = "Tên hàng hóa không được rỗng !"
                e.Valid = False
            End If
        End If
        If View.FocusedColumn.FieldName = "soluong" And View.FocusedRowHandle <> -999997 Then
            'If e.Value Is DBNull.Value Then
            If IsDBNull(e.Value) Or IsNothing(e.Value) Then
                e.ErrorText = "số lượng hóa không được rỗng !"
                e.Valid = False
            ElseIf e.Value.ToString = "" Or CInt(e.Value) = 0 Then
                e.ErrorText = "số lượng không được bằng 0 !"
                e.Valid = False
            End If
        End If
    End Sub

    Private Sub RepositoryItemSearchLookUpEdit1_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles RepositoryItemSearchLookUpEdit1.EditValueChanging
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        Dim rowHandle As Integer = editor.Properties.GetIndexByKeyValue(e.NewValue)
        IGridView1.SetFocusedRowCellValue("tenhanghoa", editor.Properties.View.GetRowCellValue(rowHandle, "ten"))
        IGridView1.SetFocusedRowCellValue("hanghoa", editor.Properties.View.GetRowCellValue(rowHandle, "ma"))
    End Sub

    Private Sub RepositoryItemSearchLookUpEdit2_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles RepositoryItemSearchLookUpEdit2.EditValueChanging
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        Dim rowHandle As Integer = editor.Properties.GetIndexByKeyValue(e.NewValue)
        IGridView1.SetFocusedRowCellValue("tendvt", editor.Properties.View.GetRowCellValue(rowHandle, "ten"))
        IGridView1.SetFocusedRowCellValue("madvt", editor.Properties.View.GetRowCellValue(rowHandle, "ma"))
    End Sub

    Private Sub IGridView1_CellValueChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles IGridView1.CellValueChanged
        Dim view1 As GridView = CType(sender, GridView)
        If Me.IGridView1.FocusedColumn.FieldName = "hanghoa" Then
            Dim view As DataView = New DataView(Me.PcvgppDataSet.hanghoa_donvitinh)
            view.RowFilter = "hanghoa = '" & Me.IGridView1.GetRowCellValue(Me.IGridView1.FocusedRowHandle, "hanghoa") & "'"
            Me.RepositoryItemSearchLookUpEdit2.DataSource = view
        End If
        '===================== xử lý thành tiền =======================
        Dim quantity As Decimal = 0
        Dim unitPrice As Decimal = 0
        Try
            quantity = CDec(view1.GetRowCellValue(e.RowHandle, view1.Columns("soluong")))
            unitPrice = CDec(view1.GetRowCellValue(e.RowHandle, view1.Columns("gia")))
        Catch ex As Exception

        End Try

        If e.Column.FieldName = "gia" Then
            view1.SetRowCellValue(e.RowHandle, view1.Columns("thanhtien"), quantity * unitPrice)
        End If
    End Sub

    Private Sub KhachhangSearchLookUpEdit_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles KhachhangSearchLookUpEdit.EditValueChanging
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        Dim rowHandle As Integer = editor.Properties.GetIndexByKeyValue(e.NewValue)
        'Dim rowhandle As Integer = Me.KhachhangSearchLookUpEdit.Properties.GetIndexByKeyValue(e.NewValue)
        Me.DiachiTextEdit.EditValue = editor.Properties.View.GetRowCellValue(rowHandle, "diachi")
    End Sub

    Private Sub KhachhangSearchLookUpEdit_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles KhachhangSearchLookUpEdit.GotFocus
        Me.KhachhangSearchLookUpEdit.ShowPopup()
    End Sub

    Private Sub KhachhangSearchLookUpEdit_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles KhachhangSearchLookUpEdit.KeyDown
        If (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab) And (state = 1 Or state = 2) Then
            Me.XuatBindingSource.EndEdit()
            Me.IGridView1.AddNewRow() ' tạo dòng mới
            Me.IGridView1.SetFocusedRowCellValue("ma", Me.MaTextEdit.EditValue)
            Me.IGridView1.SetFocusedRowCellValue("tenhanghoa", "")
            Me.batFocus()
            Dim col As GridColumn = IGridView1.Columns("hanghoa")
            Me.IGridView1.FocusedColumn = col
            Me.IGridView1.ShowEditor()
            Dim editor As SearchLookUpEdit = TryCast(IGridView1.ActiveEditor, SearchLookUpEdit)
            editor.ShowPopup()
        End If
    End Sub

    Private Sub IGridView3_FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles IGridView3.FocusedRowChanged
        Try
            Me.XuatBindingSource.Position = Me.XuatBindingSource.Find("ma", Me.IGridView3.GetGroupRowValue(Me.IGridView3.FocusedRowHandle))
        Catch ex As Exception

        End Try
    End Sub

    Private Sub XuatchitietIGridControl_ProcessGridKey(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles XuatchitietIGridControl.ProcessGridKey
        If (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab) And (state = 1 Or state = 2) AndAlso Me.IGridView1.FocusedColumn.FieldName.Equals("thanhtien") Then
            Me.IGridView1.AddNewRow()
            Me.IGridView1.SetFocusedRowCellValue("ma", Me.MaTextEdit.EditValue)
            Me.IGridView1.SetFocusedRowCellValue("tenhanghoa", "")
            Dim col As GridColumn = IGridView1.Columns("hanghoa")
            Me.IGridView1.FocusedColumn = col
            Me.IGridView1.ShowEditor()
            Dim editor As SearchLookUpEdit = TryCast(IGridView1.ActiveEditor, SearchLookUpEdit)
            editor.ShowPopup()
        End If
    End Sub

    'Private Sub IGridView1_ShownEditor(ByVal sender As Object, ByVal e As System.EventArgs) Handles IGridView1.ShownEditor
    '    Dim view As DevExpress.XtraGrid.Views.Grid.GridView = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
    '    If view.FocusedColumn.FieldName = "madvt" AndAlso TypeOf view.ActiveEditor Is GridLookUpEdit Then
    '        Dim edit As GridLookUpEdit = CType(view.ActiveEditor, GridLookUpEdit)
    '        edit.Properties.DataSource = HanghoadonvitinhBindingSource
    '        edit.Properties.DisplayMember = "ma"
    '        edit.Properties.ValueMember = "ma"
    '    End If
    '    Dim view1 As ColumnView = CType(sender, ColumnView)
    '    view1.ActiveEditor.IsModified = True
    'End Sub
    Private Sub ShowGridPreview()
        ' Check whether the XtraGrid control can be previewed. 
        If Not XuatchitietIGridControl.IsPrintingAvailable Then
            MessageBox.Show("The 'DevExpress.XtraPrinting' Library is not found", "Error")
            Return
        End If
        ' Opens the Preview window. 
        'Me.IGridControl1.ShowPrintPreview()
        'IGridControl1.ShowRibbonPrintPreview()
        Me.XuatchitietIGridControl.ShowRibbonPrintPreview()
    End Sub
    Private Sub BarButtonItemIn_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemIn.ItemClick
        ShowGridPreview()
    End Sub
End Class